<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <div style="width:100%;">
              <el-col>
                  <div ref="buttondiv">
                      <vxe-toolbar>
                          <template v-slot:buttons style="width:100%">
                              <table style="width:100%">
                                  <tr>
                                      <td>
                                          <table>
                                              <tr>
                                                  <td>检验仪器</td>
                                                  <td>
                                                      <rm-ddl-instrument :appendtobody="true" @change="labinstrumentchange" v-model="labinstrumentval" width="180px" :clearable="false" ref="instrinput" defaultflag="1" prgno="LIS825"></rm-ddl-instrument>
                                                  </td>
                                                  <td>快速查询</td>
                                                  <td>
                                                      <el-input style="width:180px" v-model="searchtext" placeholder="请输入通道号或抗生素项目"></el-input>
                                                  </td>
                                              </tr>
                                          </table>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td style="text-align:right">
                                          <div style="text-align:right;width:100%">
                                              <table style="width:100%">
                                                  <tr>
                                                      <td style="align:right">
                                                          <el-button @click="AddRow()" icon="el-icon-plus" v-has="'PADD'">新增</el-button>
                                                          <el-button @click="DeleteRow()" icon="el-icon-delete" v-has="'PDELETE'">删除</el-button>
                                                          <el-button @click="SaveUpdate()" icon="el-icon-document" v-has="'PMODIFY'">保存</el-button>
                                                          <el-button @click="ExportFile()" icon="el-icon-document">导出</el-button>
                                                          <el-button @click="ImportFile()" icon="el-icon-document">导入</el-button>
                                                      </td>
                                                  </tr>
                                              </table>
                                          </div>
                                      </td>
                                  </tr>
                              </table>
                          </template>
                      </vxe-toolbar>
                  </div>
              </el-col>
          </div>
      </div>
      <div class="pagecenter">
          <div ref="xTableDiv" style="height:100%;">
              <vxe-table :data="list" :loading="loading" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: false, showIcon: false }" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row ref="xTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                  <vxe-table-column field="interno" title="通道号" :edit-render="{name: 'input', autoselect: true}" width="200px"></vxe-table-column>
                  <vxe-table-column field="medcode" title="对应抗生素代码" width="200px" :edit-render="{name: 'input', autoselect: true}">
                      <template v-slot:edit="{ row }">
                          <el-input @dblclick.native="dialogRptVisible=true,tempRptItem=row" @keyup.space.native="dialogRptVisible=true,tempRptItem=row" v-model="row.medcode" style="width:100%;height:20px" :autofocus="true" readonly></el-input>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="lastusetime" title="最后使用时间" width="120px"></vxe-table-column>
                  <vxe-table-column field="medname" title="抗生素名称" :edit-render="{name: 'input', autoselect: true}" width="200px"></vxe-table-column>
              </vxe-table>
          </div>
      </div>

      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="抗生素项目" :visible.sync="dialogRptVisible" ref="rptdialog">
          <rm-pop-common @change="addrptitem" @cancel="dialogRptVisible=false;" :multiple="false" datatype="labmed"></rm-pop-common>
      </el-dialog>

  </div>
</template>


<script>
import { Promise } from "q";
import { invalid } from "moment";
export default {
  name: "LIS825",
  data() {
      return {
          loading: false,
          showunitreqonly: false,
          germflag: false,
          labinstrumentval: "",
          labinstrumentname: "",
          dialogRptVisible: false,
          rptunitid: 6,
          DelIndex: -1,
          tempRowIndex: -1,
          tempinterno: "",
          AddArray: "",
          searchtext: "",
          NewArr: [],
          UpdateArr: [],
          tableData: []
      };
  },
  computed: {
      list() {
          let filterName = this.searchtext.trim();
          if (filterName) {
              let filterRE = new RegExp(filterName, "gi");
              let num = this.AddArray;
              let rest = this.tableData.filter(item => {
                  return item.interno.toUpperCase().indexOf(filterName.toUpperCase()) > -1 || (item.rptitemshow ? item.rptitemshow.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || item.interno == num;
              });
              return rest;
          } else {
              return this.tableData;
          }
      }
  },
  created() {},
  watch: {
      labinstrumentval(val) {
          this.InitPageData();
      },
      searchtext(val) {
          var length = this.tableData.length;
          if (this.AddArray.length > 0) {
              this.AddArray.length = 0;
          }
          this.$nextTick(() => {
              var row = this.$refs.xTable.getCurrentRow();
              var aftersearchrow = this.$refs.xTable.tableData.filter(item => {
                  return item.interno == row.interno;
              });
              if (aftersearchrow.length == 0) {
                  if (this.$refs.xTable.tableData.length > 0) row = this.$refs.xTable.tableData[0];
                  if (row.interno) {
                      this.$refs.xTable.setCurrentRow(row);
                      this.tempRowIndex = this.$refs.xTable.getRowIndex(row);
                  }
              }
          });
      }
  },
  mounted() {},
  updated() {},
  methods: {
      InitPageData() {
          this.FindInstrItem();
      },
      rowClassName({ row, rowIndex }) {
          if (this.NewArr.indexOf(row.instrid + "") > -1) {
              return "Add";
          }
          if (this.UpdateArr.indexOf(row.instrid + "") > -1) {
              return "Update";
          }
      },
      labinstrumentchange(code, name, row) {
          this.labinstrumentval = code;
          this.labinstrumentname = name;
          this.rptunitid = row.rptunitid;
          this.nowinstrument = row.instrname;
          this.NewArr = [];
          this.UpdateArr = [];
          this.FindInstrItem();
          this.tableInstrData = [];
      },
      RptChangeEvent(code, name, row) {
          //this.InstrItem.rpt_itemcode = code;
          this.$nextTick(() => {
              this.$refs.inputrptitem.$refs.ddlrptitemSelect.focus();
          });
      },
      SpecChange(code, row) {
          row.specimencode = code;
      },
      germchange(event) {
          var germ = event;
      },
      addrptitem(c, n, row) {
          if (this.$refs.xTable.tableFullData.filter(item => item.rpt_itemcode == c).length > 0) {
              this.$alert("不能选择相同的项目", "错误");
          } else {
              this.tempRptItem.medname = n;
              this.tempRptItem.medcode = c;
              this.InstrItem = this.tempRptItem;
              this.dialogRptVisible = false;
          }
      },
      SaveUpdate() {
          var record = this.$refs.xTable.getRecordset();
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS825",
                  method: "post",
                  data: {
                      action: "save",
                      urec: record,
                      instrid: this.labinstrumentval
                  }
              })
              .then(res => {
                  if (res.errcode == "1") {
                      this.$message({
                          message: "保存成功",
                          type: "success"
                      });
                      this.FindInstrItem();
                  } else {
                      this.$alert(res.errmsg, "错误");
                  }
              });
      },
      FindInstrItem() {
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS825",
                  method: "post",
                  data: {
                      action: "query",
                      instrid: this.labinstrumentval
                  }
              })
              .then(res => {
                  if (res) {
                      this.tableData = res;
                  }
              });
      },
      AddRow() {
          if (this.labinstrumentval) {
              var row = { interno: "", medname: "", medcode: "" };
              this.$refs.xTable.insertAt(row, -1).then(rows => {
                  this.$refs.xTable.setCurrentRow(rows.row);
              });
          } else {
              this.$alert("请选择仪器!", "提示");
          }
      },
      DeleteRow() {
          // let row = this.$refs.xTable.getCurrentRow();
          // this.$refs.xTable.remove(row);
          this.$confirm("确定要删除这条通道号记录吗?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              focusCancelButton: false,
              type: "warning"
          }).then(() => {
              this.$table.DelRecordSelect(this.$refs.xTable, this.DelIndex, this);
          });
      },
      ImportFile() {
          this.$rm_uploadFiles({
              type: "文件上传",
              prgname: "LIS825",
              param1: this.labinstrumentval,
              btn: {
                  confirmBtnText: "立即上传",
                  cancelBtnText: "取消"
              }
          })
              .then(res => {
                  if (res.flag == "1") {
                      this.$notify.success({
                          title: "成功",
                          message: `文件上传成功`
                      });
                      this.FindInstrItem();
                  } else {
                      this.$notify.error({
                          title: "错误",
                          message: `文件上传失败`
                      });
                  }
              })
              .catch(e => {
                  console.log("error", e);
              });
      },
      ExportFile() {
          let columns = this.$refs.xTable.getTableColumn().tableColumn;
          let exportcolumn = [];
          for (let i = 0; i < columns.length; i++) {
              if (columns[i].property != "lastusetime") exportcolumn.push({ field: columns[i].property, title: columns[i].title });
          }
          let datas = this.tableData;

          this.$pub.exportTableExcel(datas, exportcolumn, "LIS825抗生素通道号.xlsx");

          // var p = { prgno: "LIS141", instrid: this.labinstrumentval, style: "dat" };
          // this.$pub.commexport(this, p, `仪器通道号.dat`);
      }
  }
};
</script>

<style scoped>
/deep/.Update {
  color: #5050fa;
}
/deep/.Add {
  color: #b47c7c;
}
/deep/.el-input.is-disabled .el-input__inner {
  color: black;
}
/deep/.el-checkbox.is-disabled .el-checkbox__label {
  color: black;
}
/deep/.el-textarea.is-disabled .el-textarea__inner {
  color: black;
}
/deep/.vxe-button--wrapper {
  width: 100%;
}
.pagetop {
  left: 0;
  right: 0;
  height: 72px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 76px;
  width: 100%;
  left: 0;
  bottom: 0px;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 645px;
  right: 0;
}

.middle-left {
  position: absolute;
  height: 100%;
  width: 640px;
  left: 0px;
  top: 0;
}

table tr td:nth-child(odd) {
  text-align: right;
  line-height: 32px;
  white-space: nowrap;
}
table tr td:nth-child(even) {
  text-align: left;
}
table {
  font-size: 12px;
}
td {
  padding: 0 5px 0 0;
}
/deep/.el-checkbox__inner::after {
  border: 2px solid #000000 !important;
  box-sizing: content-box;
  content: "";
  border-left: 0 !important;
  border-top: 0 !important;
  height: 7px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg) scaleY(0);
  width: 3px;
  transition: transform 0.15s ease-in 0.05s;
  transform-origin: center;
}
/deep/.el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}
/deep/ .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}
/deep/.el-input--suffix .el-input__inner {
  padding-right: 0px;
}
</style>